<template>
  <div class="app-container">
    <FloatMenu />
    <div>
      <el-form
        ref="minusForm"
        :inline="true"
        :model="dataJson.searchForm"
        label-position="getLabelPosition()"
      >

        <el-form-item>
          <select-dict
            v-model="dataJson.searchForm.status"
            :para="CONSTANTS.DICT_B_AR_STATUS"
            init-placeholder="请选择状态"
          />
        </el-form-item>

        <el-form-item>
          <select-dict
            v-model="dataJson.searchForm.type"
            :para="CONSTANTS.DICT_B_AR_TYPE"
            init-placeholder="业务类型"
          />
        </el-form-item>

        <el-form-item>
          <el-input
            v-model.trim="dataJson.searchForm.so_contract_code"
            clearable
            placeholder="合同编号"
            @keyup.enter.native="handleSearch"
          />
        </el-form-item>

        <el-form-item>
          <select-se-seller
            v-if="!isSellerDisabled"
            v-model.trim="dataJson.searchForm.seller_name"
            :placeholder="'请选择主体企业'"
            placement="left"
            @keyup.enter.native="handleSearch"
            @onReturnData="handleSellerReturnDataName"
          />
          <el-input
            v-if="isSellerDisabled"
            v-model.trim="dataJson.searchForm.seller_name"
            disabled
            placeholder="主体企业"
            @keyup.enter.native="handleSearch"
          />
        </el-form-item>

        <el-form-item>
          <select-cp-customer
            v-if="!isCustomerDisabled"
            v-model.trim="dataJson.searchForm.customer_name"
            :placeholder="'请选择客户'"
            placement="left"
            @keyup.enter.native="handleSearch"
            @onReturnData="handleCustomerReturnDataName"
          />
          <el-input
            v-if="isCustomerDisabled"
            v-model.trim="dataJson.searchForm.customer_name"
            disabled
            placeholder="客户"
            @keyup.enter.native="handleSearch"
          />
        </el-form-item>

        <el-form-item style="float:right">
          <el-button
            v-popover:popover
            type="primary"
            plain
            @click="doResetSearch"
          >重置
          </el-button>
        </el-form-item>

        <el-form-item style="float:right">
          <el-button
            type="primary"
            plain
            icon="el-icon-search"
            :loading="settings.loading"
            @click="handleSearch"
          >查询
          </el-button>
        </el-form-item>

      </el-form>
    </div>
    <!-- 合计行 -->
    <div class="div-sum">
      <div class="right">
        <span class="count-title">申请收款总金额：</span><span class="count-data">{{ dataJson.sumData.receivable_amount_total == null ? 0 : formatCurrency(dataJson.sumData.receivable_amount_total,true) }}</span>
        <span class="count-title">已收款总金额：</span><span class="count-data">{{ dataJson.sumData.received_amount_total == null ? 0 : formatCurrency(dataJson.sumData.received_amount_total,true) }}</span>
        <span class="count-title">收款中总金额：</span><span class="count-data">{{ dataJson.sumData.receiving_amount_total == null ? 0 : formatCurrency(dataJson.sumData.receiving_amount_total,true) }}</span>
        <span class="count-title">未收款总金额：</span><span class="count-data">{{ dataJson.sumData.unreceive_amount_total == null ? 0 : formatCurrency(dataJson.sumData.unreceive_amount_total,true) }}</span>
        <span class="count-title">退款总金额：</span><span class="count-data">{{ dataJson.sumData.refunded_amount_total == null ? 0 : formatCurrency(dataJson.sumData.refunded_amount_total,true) }}</span>
        <span class="count-title">中止总金额：</span><span class="count-data">{{ dataJson.sumData.stopreceive_amount_total == null ? 0 : formatCurrency(dataJson.sumData.stopreceive_amount_total,true) }}</span>
      </div>
    </div>

    <el-table
      ref="multipleTable"
      v-loading="settings.loading"
      columns_index_key="true"
      :data="dataJson.listData"
      :element-loading-text="'正在拼命加载中...'"
      element-loading-background="rgba(255, 255, 255, 0.5)"
      :height="settings.tableHeight"
      stripe
      border
      fit
      highlight-current-row
      :default-sort="{prop: 'u_time', order: 'descending'}"
      style="width: 100%"
      :cell-class-name="tableCellClassName"
      @row-click="handleRowClick"
      @row-dblclick="handleRowDbClick"
      @sort-change="handleSortChange"
      @selection-change="handleSelectionChange"
      @current-change="handleCurrentChange"
    >
      <el-table-column
        v-if="settings.exportModel"
        type="selection"
        width="45"
        prop="id"
      />
      <el-table-column
        type="index"
        width="45"
        prop="No"
        label="No"
      />
      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="150"
        prop="code"
        label="收款管理编号"
        align="left"
      />
      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="150"
        prop="type_name"
        label="业务类型"
        align="left"
      />
      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="120"
        prop="seller_name"
        label="主体企业（收款方）"
        align="left"
      />
      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="160"
        prop="customer_name"
        label="客户（付款方）"
        align="left"
      />
      <el-table-column
        label="关联合同"
        align="center"
        :merge-group="true"
      >
        <el-table-column
          :merge-cells="true"
          min-width="120"
          label="合同号"
        >
          <template v-slot="scope">
            <div
              v-for="(item, index) in scope.row.soOrderListData"
              :key="index"
              :class="getClass(index, scope.row.soOrderListData.length)"
            > {{ item.so_contract_code ==null?'-':item.so_contract_code }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          :merge-cells="true"
          min-width="100"
          label="订单号"
          align="left"
        >
          <template v-slot="scope">
            <div
              v-for="(item, index) in scope.row.soOrderListData"
              :key="index"
              :class="getClass(index, scope.row.soOrderListData.length)"
            > {{ item.so_order_code }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          :merge-cells="true"
          min-width="130"
          label="商品"
          align="left"
        >
          <template v-slot="scope">
            <div
              v-for="(item, index) in scope.row.soOrderListData"
              :key="index"
              :class="getClass(index, scope.row.soOrderListData.length)"
            > {{ item.so_goods == null ? '-' : item.so_goods }}
            </div>
          </template>
        </el-table-column>

      </el-table-column>

      <el-table-column
        label="收款信息"
        align="center"
        :merge-group="true"
      >
        <el-table-column
          :merge-cells="true"
          min-width="120"
          label="收款账户"
        >
          <template v-slot="scope">
            <div
              v-for="(item, index) in scope.row.bankListData"
              :key="index"
              :class="getClass(index, scope.row.bankListData.length)"
            > {{ item.account_number }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          :merge-cells="true"
          min-width="100"
          label="收款类型"
          align="left"
        >
          <template v-slot="scope">
            <div
              v-for="(item, index) in scope.row.bankListData"
              :key="index"
              :class="getClass(index, scope.row.bankListData.length)"
            > {{ item.accounts_purpose_type_name }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          :merge-cells="true"
          min-width="100"
          label="收款金额"
          align="right"
        >
          <template v-slot="scope">
            <div
              v-for="(item, index) in scope.row.bankListData"
              :key="index"
              :class="getClass(index, scope.row.bankListData.length)"
            > {{ item.receivable_amount == null ? '' : formatCurrency(item.receivable_amount, true) }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          :merge-cells="true"
          min-width="100"
          label="备注"
          align="left"
        >
          <template v-slot="scope">
            <div
              v-for="(item, index) in scope.row.bankListData"
              :key="index"
              :class="getClass(index, scope.row.bankListData.length)"
            > {{ item.remark }}
            </div>
          </template>
        </el-table-column>

      </el-table-column>

      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="160"
        prop="receive_status_name"
        label="收款状态"
        align="left"
      />

      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="160"
        prop="receivable_amount"
        label="申请收款总金额"
        align="right"
      >
        <template v-slot="scope">
          {{ scope.row.receivable_amount == null ? '-' : formatCurrency(scope.row.receivable_amount, true) }}
        </template>
      </el-table-column>

      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="160"
        prop="received_amount"
        label="已收款总金额"
        align="right"
      >
        <template v-slot="scope">
          {{ scope.row.received_amount == null ? '-' : formatCurrency(scope.row.received_amount, true) }}
        </template>
      </el-table-column>

      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="160"
        prop="receiving_amount"
        label="收款中总金额"
        align="right"
      >
        <template v-slot="scope">
          {{ scope.row.receiving_amount == null ? '-' : formatCurrency(scope.row.receiving_amount, true) }}
        </template>
      </el-table-column>

      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="160"
        prop="unreceive_amount"
        label="未收款总金额"
        align="right"
      >
        <template v-slot="scope">
          {{ scope.row.unreceive_amount == null ? '-' : formatCurrency(scope.row.unreceive_amount, true) }}
        </template>
      </el-table-column>

      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="160"
        prop="refunded_amount"
        label="退款总金额"
        align="right"
      >
        <template v-slot="scope">
          {{ scope.row.refunded_amount == null ? '-' : formatCurrency(scope.row.refunded_amount, true) }}
        </template>
      </el-table-column>

      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="160"
        prop="remark"
        label="备注"
        align="left"
      />

      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="120"
        prop="c_name"
        label="创建人"
        align="left"
      />
      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="150"
        prop="c_time"
        label="创建时间"
        align="left"
      >
        <template v-slot="scope">
          {{ scope.row.c_time == null?'':formatDateTime(scope.row.c_time) }}
        </template>
      </el-table-column>
      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="150"
        prop="c_name"
        label="更新人"
        align="left"
      />
      <el-table-column
        sortable="custom"
        :sort-orders="settings.sortOrders"
        :auto-fit="true"
        min-width="120"
        prop="u_time"
        label="更新时间"
        align="left"
      >
        <template v-slot="scope">
          {{ scope.row.u_time == null?'':formatDateTime(scope.row.u_time) }}
        </template>
      </el-table-column>
    </el-table>

    <pagination
      ref="minusPaging"
      :total="dataJson.paging.total"
      :page.sync="dataJson.paging.current"
      :limit.sync="dataJson.paging.size"
      @pagination="getDataList"
    />
    <!--    vue-tour组件-->
    <v-tour name="myTour" :steps="steps" :options="tourOption" />
  </div>
</template>

<style scoped>
.merge_cells0 {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-all;
  line-height: 23px;
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: 6px;
}

.merge_cells1 {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-all;
  line-height: 23px;
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #dfe6ec;
}

.merge_cells2 {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-all;
  line-height: 23px;
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid #dfe6ec;
}

.merge_cells3 {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-all;
  line-height: 23px;
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 6px;
}

::v-deep .el-tabs__item {
  height: 30px;
  line-height: 30px;
}

::v-deep .el-tabs__header {
  margin: 0 0 5px;
}

.floatRight {
  float: right;
}

.floatLeft {
  float: left;
}

.el-form-item .el-select {
  width: 100%;
}

.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 371px;
}

.el-button-group {
  margin-bottom: 10px;
}

.el-input-group__append_select,
.el-input-group__append {
  color: #ffffff;
  background-color: #1890ff;
  border-color: #1890ff;
}

.el-input-group__append_reset {
  color: #ffffff;
  background-color: #f56c6c;
  border-color: #f56c6c;
}

a {
  color: #52b5f2;
}

.div-sum {
  width: 100%;
  height: 35px;
  padding: 5px 5px;
  margin: 0;
  box-sizing: border-box;
  border-radius: 4px;
  transition: opacity 0.2s;
  background-color: #f5f7fa;
  color: #666;
  font-size: 16px;
  border-top: 1px solid #dfe6ec;
  border-left: 1px solid #dfe6ec;
  border-right: 1px solid #dfe6ec;
}

.right {
  float: right;
  margin-right: 10px;
}

.left {
  float: left;
  margin-left: 10px;
}

.count-data {
  color: #1890ff;
  font-size: 20px;
}

.count-title {
  margin-left: 10px;
}

br {
  display: block;
  margin: 10px;
  content: ' ';
}

.perfect_popper .el-form-item--mini.el-form-item {
  margin-bottom: 10px;
}

/* sumData处的 el-link */
.el-link.el-link--default {
  font-size: 16px;
  vertical-align: top;
}

.el-form-item--mini.el-form-item {
  margin-bottom: 10px;
}

.el-tabs {
  margin-bottom: 5px;
}
</style>

<script>
import {
  getListByArrefundApi,
  querySumByArrefund
} from '@/api/40_business/20_so/ar/ar'
import Pagination from '@/components/Pagination/index.vue'
import elDragDialog from '@/directive/el-drag-dialog'
import deepCopy from 'deep-copy'
import mixin from './mixin'
import permission from '@/directive/permission' // 权限判断指令
import constants_dict from '@/common/constants/constants_dict'
import SelectDict from '@/components/00_dict/select/SelectDict.vue'
import SelectCpCustomer from '@/views/20_master/enterprise/dialog/selectgrid/counterparty/customer/index.vue'
import SelectSeSeller from '@/views/20_master/enterprise/dialog/selectgrid/system_enterprise/seller/index.vue'

export default {
  components: { Pagination, SelectDict, SelectCpCustomer, SelectSeSeller },
  directives: { elDragDialog, permission },
  mixins: [mixin],
  props: {
    data: {
      type: Object,
      default: null
    }
  },
  data () {
    return {
      dataJson: {
        tabsCount: {
          all: 0,
          todo: 0
        },
        tabs: {
          active: ''
        },
        // 查询使用的json
        searchForm: {
          code: '',
          plan_code: '',
          customer_name: '',
          customer_id: '',
          seller_name: '',
          seller_id: '',
          // 翻页条件
          pageCondition: deepCopy(this.PARAMETERS.PAGE_CONDITION),
          // 查询条件
          // 启动日期
          batch: '',
          active_tabs_index: '' // 当前被激活的页签
          // 是否包含放货指令
        },
        todoSearchForm: {},
        // 分页控件的json
        paging: deepCopy(this.PARAMETERS.PAGE_JSON),
        // table使用的json
        listData: null,
        sumData: {
          actual_count: 0,
          actual_weight: 0,
          sync_error_count: 0,
          // 合计数据 - 使用学习代码的数据结构
          receivable_amount_total: 0,
          received_amount_total: 0,
          receiving_amount_total: 0,
          unreceive_amount_total: 0,
          refunded_amount_total: 0,
          stopreceive_amount_total: 0
        },
        customerComboList: [],
        // 单条数据 json的，初始化原始数据
        // 单条数据 json
        currentJson: null,
        tempJson: {
          remark: '',
          cancel_files: []
        },
        inputSettings: {
          maxLength: {
            name: 20,
            config_key: 20,
            value: 50,
            descr: 200
          }
        },
        // 当前表格中的索引，第几条
        rowIndex: 0,
        // 当前选中的行（checkbox）
        multipleSelection: []
      },
      // 打印窗口的状态
      popPrint: {
        dialogVisible: false,
        data: null
      },
      // 下推窗口的状态
      popPush: {
        dialogVisible: false,
        editStatus: null,
        data: null
      },
      // 作废窗口的状态
      popCancel: {
        dialogVisible: false,
        editStatus: null,
        data: null
      },
      // 中止收款窗口的状态
      popStop: {
        dialogVisible: false,
        editStatus: null,
        data: null
      },
      // 页面设置json
      settings: {
        // 表格排序规则
        sortOrders: deepCopy(this.PARAMETERS.SORT_PARA),
        // 导出模式
        exportModel: false,
        // 按钮状态
        btnStatus: {
          showDel: false,
          showUpdate: false,
          showView: false,
          showExport: false,
          hidenExport: true,
          showApprove: false,
          showPrint: false,
          showPush: false,
          showStopPush: false,
          showCancel: false
        },
        // loading 状态
        loading: true,
        tableHeight: this.setUIheight(),
        duration: 4000,
        isCustomerDisabled: false,
        isSellerDisabled: false
      },
      // vue-tour组件
      tourOption: {
        useKeyboardNavigation: false, // 是否通过键盘的←, → 和 ESC 控制指引
        labels: { // 指引项的按钮文案
          buttonStop: '结束' // 结束文案
        },
        highlight: false // 是否高亮显示激活的的target项
      },
      steps: [
        {
          target: '.el-table-column--selection', // 当前项的id或class或data-v-step属性
          content: '请通过点击多选框，选择要导出的数据！', // 当前项指引内容
          params: {
            placement: 'top', // 指引在target的位置，支持上、下、左、右
            highlight: false, // 当前项激活时是否高亮显示
            enableScrolling: false // 指引到当前项时是否滚动轴滚动到改项位置
          },
          // 在进行下一步时处理UI渲染或异步操作，例如打开弹窗，调用api等。当执行reject时，指引不会执行下一步
          before: type => new Promise((resolve, reject) => {
            // 耗时的UI渲染或异步操作
            resolve('foo')
          })
        }
      ],
      screenNum: 0
    }
  },
  computed: {
    // 控制客户是否禁用
    isCustomerDisabled () {
      return this.settings.isCustomerDisabled
    },
    // 控制主体企业是否禁用
    isSellerDisabled () {
      return this.settings.isSellerDisabled
    }
  },
  // 监听器
  watch: {
    // 全屏loading
    'settings.loading': {
      handler (newVal, oldVal) {
        switch (newVal) {
          case true:
            this.showLoading('正在查询，请稍后...')
            break
          case false:
            this.closeLoading()
            break
        }
      }
    }
  },
  beforeDestroy () {
  },
  created () {
  },
  beforeUpdate () {
    // 重新布局表格
    this.$nextTick(() => {
      this.$refs.multipleTable.doLayout()
    })
  },
  mounted () {
    // 描绘完成
    this.init()
  },
  destroyed () {
  },
  methods: {
    // 初始化页面
    init (parm) {
      // 处理传入的data参数
      this.handleInitData()

      // 将props.data参数合并到searchForm中，保留原有的pageCondition等结构
      if (this.data) {
        Object.assign(this.dataJson.searchForm, deepCopy(this.data))
      }
      // 初始化查询
      this.getDataList()
      // 数据初始化
      this.dataJson.tempJson = deepCopy(this.$options.data.call(this).dataJson.tempJson)
    },
    // 处理传入的data参数
    handleInitData () {
      if (this.data) {
        // 如果存在customer_id，客户控件不可用，并且设置
        if (this.data.customer_id) {
          this.settings.isCustomerDisabled = true
          this.dataJson.searchForm.customer_name = this.data.customer_name
          this.dataJson.searchForm.customer_id = this.data.customer_id
        }

        // 如果存在seller_id，主体企业控件不可用，并且设置
        if (this.data.seller_id) {
          this.settings.isSellerDisabled = true
          this.dataJson.searchForm.seller_name = this.data.seller_name
          this.dataJson.searchForm.seller_id = this.data.seller_id
        }
      }
    },
    // 获取行索引
    getRowIndex (row) {
      const _index = this.dataJson.listData.lastIndexOf(row)
      return _index
    },
    // 行点击
    handleRowClick (row) {
      this.dataJson.rowIndex = this.getRowIndex(row)
    },
    // 行双点击，仅在dialog中有效
    handleRowDbClick (row) {
      this.dataJson.rowIndex = this.getRowIndex(row)
      var _data = deepCopy(row)
      this.$emit('rowDbClick', _data)
    },
    handleSearch () {
      // 查询
      this.dataJson.searchForm.pageCondition.current = 1
      this.dataJson.paging.current = 1
      this.getDataList()
      // 清空选择
      this.dataJson.multipleSelection = []
      this.$refs.multipleTable.clearSelection()
    },
    handleSortChange (column) {
      // 服务器端排序
      if (column.order === 'ascending') {
        this.dataJson.searchForm.pageCondition.sort = column.prop
      } else if (column.order === 'descending') {
        this.dataJson.searchForm.pageCondition.sort = '-' + column.prop
      }
      this.getDataList()
    },
    getDataList () {
      // 启动全屏loading
      this.showLoading('正在查询，请稍后...')

      this.dataJson.searchForm.pageCondition.current = this.dataJson.paging.current
      this.dataJson.searchForm.pageCondition.size = this.dataJson.paging.size
      // 查询逻辑
      this.settings.loading = true
      getListByArrefundApi(this.dataJson.searchForm).then(response => {
        this.dataJson.listData = response.data.records
        this.dataJson.paging = response.data
        this.dataJson.paging.records = {}
      }).finally(() => {
        this.settings.loading = false
      })
      // 查询合计信息
      querySumByArrefund(this.dataJson.searchForm).then(response => {
        if (response.data !== null) {
          this.dataJson.sumData = response.data
        } else {
          this.dataJson.sumData.receivable_amount_total = 0
          this.dataJson.sumData.received_amount_total = 0
          this.dataJson.sumData.receiving_amount_total = 0
          this.dataJson.sumData.unreceive_amount_total = 0
          this.dataJson.sumData.refunded_amount_total = 0
          this.dataJson.sumData.stopreceive_amount_total = 0
        }
      }).finally(() => {
        this.settings.loading = false
      })
    },
    // 重置查询区域
    doResetSearch () {
      // 保存从data中传递的客户和主体企业信息
      const preservedCustomerName = this.data && this.data.customer_id ? this.data.customer_name : ''
      const preservedCustomerId = this.data && this.data.customer_id ? this.data.customer_id : ''
      const preservedSellerName = this.data && this.data.seller_id ? this.data.seller_name : ''
      const preservedSellerId = this.data && this.data.seller_id ? this.data.seller_id : ''

      this.dataJson.searchForm = this.$options.data.call(this).dataJson.searchForm

      // 如果存在customer_id，重置后不复原customer相关信息
      if (this.data && this.data.customer_id) {
        this.dataJson.searchForm.customer_name = preservedCustomerName
        this.dataJson.searchForm.customer_id = preservedCustomerId
      }

      // 如果存在seller_id，重置后不复原seller相关信息
      if (this.data && this.data.seller_id) {
        this.dataJson.searchForm.seller_name = preservedSellerName
        this.dataJson.searchForm.seller_id = preservedSellerId
      }
    },
    // 获取row-key
    getRowKeys (row) {
      return row.id
    },
    // table选择框
    handleSelectionChange (val) {
      this.dataJson.multipleSelection = val
    },
    getClass (index, length) {
      if (length === 1) {
        return 'merge_cells0 cell'
      } else if (index === 0) {
        return 'merge_cells1 cell'
      } else if (index === length - 1) {
        return 'merge_cells3 cell'
      } else {
        return 'merge_cells2 cell'
      }
    },
    /**
     * 打印弹窗关闭
     */
    handlePushCancel () {
      this.popPush.dialogVisible = false
    },
    /**
     * 完成导出
     */
    handleExportOk () {
      this.settings.btnStatus.hidenExport = true
      this.settings.btnStatus.showExport = false
      this.settings.exportModel = false
    },
    /**
     * 切换到导出模式
     */
    handleModelOpen () {
      this.settings.exportModel = true
      this.settings.btnStatus.hidenExport = false
      this.$tours['myTour'].start()
    },
    // 导出按钮
    handleExport () {
      // 没有选择任何数据的情况
      if (this.dataJson.multipleSelection.length <= 0) {
        this.$alert('请在表格中选择数据进行导出', '未选择数据错误', {
          confirmButtonText: '关闭',
          type: 'error'
        }).then(() => {
          this.settings.btnStatus.showExport = false
        })
      } else if (this.dataJson.multipleSelection.length === this.dataJson.listData.length) {
        // 选择全部的时候
        this.$confirm('请选择：当前页数据导出，全数据导出？', '确认信息', {
          distinguishCancelAndClose: true,
          confirmButtonText: '全部导出',
          cancelButtonText: '当前页数据导出'
        }).then(() => {
          this.handleExportAllData()
        }).catch(action => {
          // 右上角X
          if (action !== 'close') {
            // 当前页所选择的数据导出
            this.handleExportSelectionData()
          }
        })
      } else {
        // 部分数据导出
        this.handleExportSelectionData()
      }
    },
    // 全部数据导出
    tableCellClassName ({ row, column, rowIndex, columnIndex }) {
      if (column.property === 'validate_vehicle' && row.validate_vehicle !== '1') {
        return 'warning-cell'
      }
      return ''
    },
    // 作废弹窗关闭
    handleCloseDialogCancelOk (val) {
      this.popCancel.dialogVisible = false
    },
    // 中止收款弹窗关闭
    handleCloseDialogStopOk (val) {
      this.popStop.dialogVisible = false
    },
    // 获取审批状态文本
    getApprovalStatusText (row) {
      if (!row.next_approve_name) {
        return row.next_approve_name || ''
      }

      // 状态为1或4时，显示"待用户"+next_approve_name+"审批"
      if (row.status === constants_dict.DICT_B_AR_STATUS_ONE || row.status === constants_dict.DICT_B_AR_STATUS_FOUR) {
        return `待用户${row.next_approve_name}审批`
      }

      // 其他状态直接显示next_approve_name
      return row.next_approve_name
    },
    handleCurrentChange (row) {
      // 设置dialog的返回
      this.$store.dispatch('popUpSearchDialog/selectedDataJson', deepCopy(row))
    },
    // 客户选择回调
    handleCustomerReturnDataName (val) {
      if (val) {
        // 正常选择客户的情况
        this.dataJson.searchForm.customer_name = val.name
        this.dataJson.searchForm.customer_id = val.id
      } else {
        // 取消或清空的情况
        this.dataJson.searchForm.customer_name = ''
        this.dataJson.searchForm.customer_id = ''
      }
    },
    // 主体企业选择回调
    handleSellerReturnDataName (val) {
      if (val) {
        // 正常选择主体企业的情况
        this.dataJson.searchForm.seller_name = val.name
        this.dataJson.searchForm.seller_id = val.id
      } else {
        // 取消或清空的情况
        this.dataJson.searchForm.seller_name = ''
        this.dataJson.searchForm.seller_id = ''
      }
    }
  }
}
</script>
